package com.admin.controller;


import com.admin.entity.Role;
import com.admin.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bean.ResponseBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author marisheng
 * @since 2019-11-21
 */
@RestController
@RequestMapping("/admin/role")
public class RoleController {


    @Autowired
    private IRoleService iRoleService;

    /**
     *查询角色
     * @return
     */
    @RequestMapping("/selRole")
    public ResponseBean selRole(){
        List list = iRoleService.selRole();
        if(list!=null&&list.size()>0){
            return new ResponseBean(200 , "角色查询成功" , list);
        }else{
            return new ResponseBean(500 , "角色查询失败" , null);
        }
    }
    @RequestMapping("/findRoleWithPage")
    public ResponseBean findRoleWithPage(int page,int limit,String roleName){
        IPage<Role> page1 = new Page<Role>(page,limit);
        QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
        if(roleName!=null&&roleName.trim().length()>0) {
            queryWrapper.like("role_name", roleName);
        }
        IPage iPage = iRoleService.page(page1,queryWrapper);
        return new ResponseBean(0,"success",iPage);
    }
}
